//
//  MenuViewController.m
//  Products_B
//
//  Created by lanou on 16/5/27.
//  Copyright © 2016年 朋学友. All rights reserved.
//

#import "MenuViewController.h"
#import "ScrollViewManager.h"
#import "LBTModel.h"
#import "YouLikeModel.h"
#import "ScrollModel.h"
#import "MenuMainModel.h"

#import "TodayNewProductTableViewCell.h"
#import "FoodSpecialistTableViewCell.h"
#import "TeaAndIcreAndLifeTableViewCell.h"
#import "SuperManTableViewCell.h"
#import "MenuZeroCollectionViewCell.h"
#import "GoodFoodTableViewCell.h"
#import "MenuSixCollectionViewCell.h"
#import "MenuShicaiCollectionViewCell.h"
#import "MenuListHeadCollectionReusableView.h"
#import "MenuShiCaiBigCollectionViewCell.h"
#import "MenuShiCaiModel.h"

#import "MenuFenleiModel.h"
#import "MenuFenleiCollectionViewCell.h"
#import "MenuListBigCollectionViewCell.h"
#import "MenuFenLeiHeadCollectionReusableView.h"
#import "MenuDetailViewController.h"
#import  "MenuFenleilistViewController.h"

#import "MenuTuiJianXInShouViewController.h"
#import "MenuTuiJIanShiCaiViewController.h"
#import "MenuTuiJianChangJingViewController.h"
#import "MenuTuiJIanCaiNiViewController.h"
#import "MenuDarenViewController.h"
#import "MenuTuijianChangjingDetailViewController.h"
#import "MenuTuiJianChangJingViewController.h"
#import "MenuJingXuanMainViewController.h"
#import "MenuFirstDetailViewController.h"
#import "MenuZhuanTiMainViewController.h"
#import "MenuZhuanTiDetailViewController.h"
#import "MenuErweimaViewController.h"
#import "MenuShiLiaoViewController.h"
#define kMenuUrl @"http://api.izhangchu.com/?methodName=SceneHome&token=0&user_id=0&version=4.4"

#define kShiCaiUrl @"http://api.izhangchu.com/?methodName=MaterialSubtype&version=4.40"

#define kFenleiUrl @"http://api.izhangchu.com/?methodName=CategoryIndex&version=4.40"
@interface MenuViewController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong)NSMutableArray *LBTModelArray;
@property (nonatomic, strong)NSMutableArray *youLikeModelArray;
@property (nonatomic, strong)NSMutableArray *youLikeTitleArray;
@property (nonatomic, strong)NSMutableArray *youLikeOtherArray;
@property (nonatomic, strong)NSMutableArray *scrollModelArray;
@property (nonatomic, strong)NSMutableArray *descArray;

@property (nonatomic, strong)NSMutableArray *oneArray;
@property (nonatomic, strong)NSMutableArray *twoArray;
@property (nonatomic, strong)NSMutableArray *threeArray;
@property (nonatomic, strong)NSMutableArray *fourArray;
@property (nonatomic, strong)NSMutableArray *fiveArray;
@property (nonatomic, strong)NSMutableArray *sixArray;
@property (nonatomic, strong)NSMutableArray *zeroArray;

@property (nonatomic, strong)NSMutableDictionary *modelDic;
@property (nonatomic, strong)NSArray *keyArray;

@property (nonatomic, strong)UIScrollView *scrollView;
@property (nonatomic, strong)UIView *leftView;
@property (nonatomic, strong)UIView *centerView;
@property (nonatomic, strong)UIView *rightView;
@property (nonatomic, strong)UIView *headView;
@property (nonatomic, strong)UIView *changeView;
@property (nonatomic, strong)UISearchBar *searchBar;
@property (nonatomic, strong)UITableView *tableView;

@property (nonatomic, assign)int one;
@property (nonatomic, assign)int three;
@property (nonatomic, assign)int two;
@property (nonatomic, assign)int four;
@property (nonatomic, assign)int five;
@property (nonatomic, assign)int six;
@property (nonatomic, assign)int  zero;

@property (nonatomic, strong)UICollectionView *collectionView;
@property (nonatomic, strong)UICollectionView *goodfoodCollection;

//  食材界面
@property (nonatomic, strong)NSMutableArray *shiCaiTitleArray;
@property (nonatomic, strong)NSMutableArray *shiCaiPicArray;
@property (nonatomic, strong)NSMutableDictionary *shiCaiDic;

@property (nonatomic, strong)UICollectionView *shiCaiCollctionView;

//  分类界面
@property (nonatomic, strong)UICollectionView *fenLeiCollectionView;
@property (nonatomic, strong)NSMutableArray *fenLeiSectionTitleArray;
@property (nonatomic, strong)NSMutableArray *fenLeiPicArray;
@property (nonatomic, strong)NSMutableDictionary *fenLeiModelDic;


@property (nonatomic, strong)NSString *xinshourumenUrl;

@property (nonatomic, strong)NSMutableArray *linkArray;
@end

@implementation MenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   //  隐藏tableBar
    self.navigationController.navigationBar.hidden = YES;
    //  不让scrollview 到处跑
    self.automaticallyAdjustsScrollViewInsets = NO;
     //  初始化两个数组
    self.youLikeOtherArray = [NSMutableArray array];
    self.youLikeTitleArray = [NSMutableArray array];
    
    
    
    //  创建上面的视图
    [self creatTopView];
    //  穿件滚动视图
    [self creatScrollView];
    //  创建头视图
    self.headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 150 + kWidth/ 4 + 10 + 50 + 30)];
//    self.headView.backgroundColor = [UIColor magentaColor];
//    [self.leftView addSubview:_headView];
    // 创建所搜框
    [self creatSearchBarVc];
  
    //  创建tableView
    [self creadTableView];
    //  左边视图下拉刷新
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [self requestData];
    }];
 

      //  食材
//     添加食材的collectionView
    [self addCollectionForShiCai];
    
 
       //  中间视图上拉刷新
    self.shiCaiCollctionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self requestShiCaiData];
    }];
    
    //  添加分类的collectionView
    [self addCollectionViewForFenlei];
    
    //  右边的下拉刷新
    self.fenLeiCollectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self requestFenLeiData];
    }];
    
    //  请求食材数据
    [self requestShiCaiData];
    //  网络请求
    [self requestData];
    
    //分类的网络请求
    [self requestFenLeiData];
    
    
}
#pragma mark - tableView 的点击方法 -
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == self.keyArray.count -1) {
        
        NSString *key = self.keyArray[indexPath.section];
        NSMutableArray *modelArray = self.modelDic[key];
        NSLog(@"%@   %@",key, modelArray);
        MenuZhuanTiDetailViewController *Vc = [[MenuZhuanTiDetailViewController alloc]init];
        
        MenuMainModel *model = modelArray[3 * indexPath.row];
       NSArray *array = [model.link componentsSeparatedByString:@"="];
        Vc.shareID = array[1];
        [self.navigationController pushViewController:Vc animated:YES];
    }
}
#pragma  mark - 食材界面每个button的点击方法 -
- (void)nameButtonAvtion:(UIButton *)sender{
    
}
#pragma  mark - collectioncell 的点击方法 -
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (collectionView == self.shiCaiCollctionView) {
   
    if (indexPath.row == 0) {
        return;
    }
    NSString *key = self.shiCaiTitleArray[indexPath.section];
    NSMutableArray *modelArray = self.shiCaiDic[key];
    MenuShiCaiModel *model = modelArray[indexPath.row-1];
    MenuDetailViewController *menuDetailVc = [[MenuDetailViewController alloc]init];
    menuDetailVc.idString = model.id;
    menuDetailVc.text = model.text;
    menuDetailVc.imageString = model.image;
    [self.navigationController pushViewController:menuDetailVc animated:YES];
   }
    if (collectionView == self.fenLeiCollectionView) {
        if (indexPath.row == 0) {
            return;
        }
        
        if (indexPath.section == self.fenLeiSectionTitleArray.count -1) {
            
            
           NSMutableArray *modelArray = self.fenLeiModelDic[self.fenLeiSectionTitleArray[indexPath.section]];
            MenuFenleiModel *model = modelArray[indexPath.row - 1];
            
            MenuShiLiaoViewController *Vc = [[MenuShiLiaoViewController alloc]init];
            Vc.department_id = model.id;
            [self.navigationController pushViewController:Vc animated:YES];
        }else{
            NSString *key = self.fenLeiSectionTitleArray[indexPath.section];
            NSMutableArray *modelArray = [self.fenLeiModelDic objectForKey:key];
            
            MenuFenleiModel *model = modelArray[indexPath.row - 1];
            NSLog(@"%@",model.id);
            MenuFenleilistViewController *fenleiListVc = [[MenuFenleilistViewController alloc]init];
            fenleiListVc.cat_id = model.id;
            [self.navigationController pushViewController:fenleiListVc animated:nil];
            
        }
        
    }
    if (self.collectionView == collectionView) {
        NSString *key = self.keyArray[0];
        NSLog(@"%@",key);
        NSMutableArray *modelArray = self.modelDic[key];
        NSLog(@"%@",modelArray);
        MenuMainModel *model = modelArray[indexPath.row *4];
        NSArray *array = [model.link componentsSeparatedByString:@"#"];
        NSLog(@"%@",array[1]);
        
        MenuFirstDetailViewController *Vc = [[MenuFirstDetailViewController alloc]init];
        Vc.dishes_id = array[1];
        
     
        [self.navigationController pushViewController:Vc animated:YES];
        
    }
}
#pragma  mark - 分类的网络请求 - 
- (void)requestFenLeiData{
    [RequestManager requestWithUrl:kFenleiUrl requestType:(RequestTypePOST) parDic:nil finish:^(NSData *data) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        self.fenLeiPicArray = [MenuFenleiModel modelPicArrayConfigureWithDic:jsonDic];
        self.fenLeiSectionTitleArray = [MenuFenleiModel modelSectionTitleConFigureWithDic:jsonDic];
        self.fenLeiModelDic = [MenuFenleiModel modelModelDataConfiggureWithDic:jsonDic];
        NSLog(@"%@",self.fenLeiModelDic[self.fenLeiSectionTitleArray[0]]);
        [self.fenLeiCollectionView.mj_header endRefreshing];
        
        [self.fenLeiCollectionView reloadData];
    } error:nil];
}
#pragma mark - 添加分类的collectionView -
- (void)addCollectionViewForFenlei{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    self.fenLeiCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight - 70 - 50) collectionViewLayout:flowLayout];
    self.fenLeiCollectionView.backgroundColor = [UIColor whiteColor];
    self.fenLeiCollectionView.delegate = self;
    self.fenLeiCollectionView.dataSource = self;
    [self.fenLeiCollectionView registerClass:[MenuFenleiCollectionViewCell class] forCellWithReuseIdentifier:@"MenuFenleiCollectionViewCell"];
    [self.fenLeiCollectionView registerClass:[MenuListBigCollectionViewCell class] forCellWithReuseIdentifier:@"MenuListBigCollectionViewCell"];
    [self.fenLeiCollectionView registerClass:[MenuFenLeiHeadCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MenuFenLeiHeadCollectionReusableView"];
    [self.rightView addSubview:_fenLeiCollectionView];
}
#pragma  mark - 食材的网路请求 
- (void)requestShiCaiData{
    [RequestManager requestWithUrl:kShiCaiUrl requestType:(RequestTypePOST) parDic:nil finish:^(NSData *data) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        self.shiCaiPicArray = [MenuShiCaiModel modelReturnPicStringWith:jsonDic];
        self.shiCaiTitleArray = [MenuShiCaiModel modelReturnSectionNameWith:jsonDic];
        self.shiCaiDic = [MenuShiCaiModel modelConfigureWithDic:jsonDic];
        [self.shiCaiCollctionView.mj_header endRefreshing];
        [self.shiCaiCollctionView reloadData];
    } error:nil];
}
#pragma mark - 返回colletionView 的分区数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    if (collectionView == self.shiCaiCollctionView) {
        return self.shiCaiTitleArray.count;
    }
    if (collectionView == self.fenLeiCollectionView) {
        return self.fenLeiSectionTitleArray.count;
    }
    return 1;
}
#pragma mark - 返回collection的 行数 -
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (collectionView == self.shiCaiCollctionView) {
        NSString *key = self.shiCaiTitleArray[section];
        return [self.shiCaiDic[key] count] + 1;
    }
    if (collectionView == self.fenLeiCollectionView) {
        NSString *key = self.fenLeiSectionTitleArray[section];
       
        return [self.fenLeiModelDic[key] count] + 1;
    }
    return 3;
}
#pragma mark - 返回collectionView的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (collectionView == self.shiCaiCollctionView) {
        if (indexPath.row == 0) {
            return CGSizeMake(100, 80);
        }
        return CGSizeMake(50, 30);
    }
    if (collectionView == self.fenLeiCollectionView) {
        if (indexPath.row == 0) {
            return CGSizeMake(100, 80);
        }
        return CGSizeMake(50, 30);
    }
    if (collectionView == self.collectionView) {
        return CGSizeMake(kWidth / 3, kWidth/3 * 1915 / 1277 + 30 + 50);
    }if (collectionView == self.goodfoodCollection){
        return CGSizeMake(kWidth / 3, kWidth/ 3 + 60);
    }
    return CGSizeMake(0, 0);
}
#pragma mark - 设置列边距 -
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    if (collectionView == self.shiCaiCollctionView) {
        return 10;
    }
    if (collectionView == self.fenLeiCollectionView) {
        return 10;
    }
    return 0;
}
#pragma mark - 设置行边距 -
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    if (collectionView == self.shiCaiCollctionView) {
        return 10;
    }
    if (collectionView == self.fenLeiCollectionView) {
        return 10;
    }
    return 0;
}

#pragma mark - 设置设置整体的上 左 下 右 ---
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    if (self.collectionView == self.shiCaiCollctionView) {
        return UIEdgeInsetsMake(0, 0, 0, 0);
    }
    return UIEdgeInsetsMake(0, 0, 0, 0);
}
#pragma mark --- 返回表头 方法 ---
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if (collectionView == self.shiCaiCollctionView) {
        if ([kind isEqualToString:UICollectionElementKindSectionHeader]){
            MenuListHeadCollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MenuListHeadCollectionReusableView" forIndexPath:indexPath];
//            headerView.backgroundColor = [UIColor redColor];
            headerView.titleLabel.text = self.shiCaiTitleArray[indexPath.section];
            return  headerView;

        }
    }
    if (collectionView == self.fenLeiCollectionView) {
        if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
            MenuFenLeiHeadCollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MenuFenLeiHeadCollectionReusableView" forIndexPath:indexPath];
            headerView.titleLabel.text = self.fenLeiSectionTitleArray[indexPath.section];
//            headerView.backgroundColor = [UIColor redColor];
            return headerView;
        }
    }
    return nil;
}

#pragma mark --- 设置表头大小 ---
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    if (collectionView == self.shiCaiCollctionView) {
        return CGSizeMake(kWidth, 40);
    }
    if (collectionView == self.fenLeiCollectionView) {
        return CGSizeMake(kWidth, 40);
    }
    return CGSizeMake(0, 0);
}
#pragma mark - 返回collectionCell -
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (collectionView == self.shiCaiCollctionView) {
        if (indexPath.row == 0) {
            MenuShiCaiBigCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MenuShiCaiBigCollectionViewCell" forIndexPath:indexPath];
//            cell.backgroundColor = [UIColor redColor];
            [cell.bigImageView sd_setImageWithURL:[NSURL URLWithString:self.shiCaiPicArray[indexPath.section]] placeholderImage:nil completed:nil];
            return cell;
        }
        MenuShicaiCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MenuShicaiCollectionViewCell" forIndexPath:indexPath];
        NSString *key = self.shiCaiTitleArray[indexPath.section];
        NSArray *modelArray = [self.shiCaiDic objectForKey:key];
        [cell.nameButton setTitle:[modelArray[indexPath.row-1] text] forState:(UIControlStateNormal)];
//        cell.nameButton.backgroundColor = [UIColor blueColor];

        cell.nameButton.userInteractionEnabled = NO;
        [cell.nameButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
//        [cell.nameButton addTarget:self action:@selector(nameButtonAvtion:) forControlEvents:(UIControlEventTouchUpInside)];
        return cell;
    }
    if (collectionView == self.fenLeiCollectionView) {
        if (indexPath.row == 0) {
            MenuListBigCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MenuListBigCollectionViewCell" forIndexPath:indexPath];
            [cell.bigImageView sd_setImageWithURL:[NSURL URLWithString:self.fenLeiPicArray[indexPath.section]] placeholderImage:nil completed:nil];
            return cell;
        }
        MenuFenleiCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MenuFenleiCollectionViewCell" forIndexPath:indexPath];
        NSString *key = self.fenLeiSectionTitleArray[indexPath.section];
        NSMutableArray *modelArray = [self.fenLeiModelDic objectForKey:key];
        NSLog(@"%@",modelArray);
        [cell.nameButton setTitle:[modelArray[indexPath.row-1] text] forState:(UIControlStateNormal)];
        [cell.nameButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        cell.nameButton.userInteractionEnabled = NO;
//        [cell.nameButton addTarget:self action:@selector(nameFenLeiButtonAvtion:) forControlEvents:(UIControlEventTouchUpInside)];
        return cell;

        
    }
    
    if (collectionView == self.collectionView) {
        MenuZeroCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MenuZeroCollectionViewCell" forIndexPath:indexPath];
        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:self.zeroArray[indexPath.row][0]] placeholderImage:nil completed:nil];
        cell.titleLabel.text = self.zeroArray[indexPath.row][2];
        cell.contentLabel.text = self.zeroArray[indexPath.row][3];
        return cell;
    }
    if (collectionView == self.goodfoodCollection){
        MenuSixCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MenuSixCollectionViewCell" forIndexPath:indexPath];
        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:self.sixArray[indexPath.row][0]] placeholderImage:nil completed:nil];
        [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:self.sixArray[indexPath.row][1]] placeholderImage:nil completed:nil];
        cell.nameLabel.text = self.sixArray[indexPath.row][2];
        return cell;
    }
    return nil;
}
//#pragma mark - 分类button的方法 - 
//- (void)nameFenLeiButtonAvtion:(UIButton *)button{
//    MenuFenleilistViewController *fenleiListVc = [[MenuFenleilistViewController alloc]init];
//    [self.navigationController pushViewController:fenleiListVc animated:nil];
//}
#pragma mark - 添加食材的collectionView-
- (void)addCollectionForShiCai{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    self.shiCaiCollctionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight - 120) collectionViewLayout:flowLayout];
    self.shiCaiCollctionView.delegate = self;
    self.shiCaiCollctionView.dataSource = self;
    [self.shiCaiCollctionView registerClass:[MenuShicaiCollectionViewCell class] forCellWithReuseIdentifier:@"MenuShicaiCollectionViewCell"];
    [self.shiCaiCollctionView registerClass:[MenuShiCaiBigCollectionViewCell class] forCellWithReuseIdentifier:@"MenuShiCaiBigCollectionViewCell"];
    //  注册表头
    [self.shiCaiCollctionView registerClass:[MenuListHeadCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MenuListHeadCollectionReusableView"];
    
    
    self.shiCaiCollctionView.delegate = self;
    self.shiCaiCollctionView.dataSource = self;
    self.shiCaiCollctionView.backgroundColor = [UIColor whiteColor];
    [self.centerView addSubview:_shiCaiCollctionView];
}

#pragma mark - 请求网络数据 -
- (void)requestData{
    
    [RequestManager requestWithUrl:kMenuUrl requestType:(RequestTypePOST) parDic:nil finish:^(NSData *data) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        
        //  轮播图model数组
        self.LBTModelArray = [LBTModel modelConfigureWithDic:jsonDic];
        
        //  轮播图的图片url数组
        NSMutableArray *lBTPicArray = [NSMutableArray array];
        for (LBTModel *model in self.LBTModelArray) {
            [lBTPicArray addObject:model.banner_picture];
        }
      
//        [ScrollViewManager viewRepeatScrollWithPicArray:lBTPicArray view:self.headView frame:CGRectMake(0, 0, kWidth, 100)];
        [ScrollViewManager viewRepeatScrollWithPicArray:lBTPicArray view:self.headView frame:CGRectMake(0, 0, kWidth, 100) tapBlock:^(NSInteger index) {
            NSLog(@"%ld",index);
            if (index == 0) {
                LBTModel *model = self.LBTModelArray[index];
                NSArray *array = [model.banner_link componentsSeparatedByString:@"="];
                MenuZhuanTiDetailViewController *Vc = [[MenuZhuanTiDetailViewController alloc]init];
                Vc.shareID = array[1];
                [self.navigationController pushViewController:Vc animated:YES];
            }
        }];
        
        self.youLikeModelArray = [YouLikeModel modelConfigureWithDic:jsonDic];
        YouLikeModel *youLikeModel = self.youLikeModelArray[0];
        self.xinshourumenUrl = youLikeModel.link;
        
        self.descArray = [MenuMainModel modelConfigureDic:jsonDic];
        
     
        self.linkArray = [MenuMainModel modelLinkConfigureDic:jsonDic];
        for (int i = 0; i < self.youLikeModelArray.count; i++) {
            if (i % 2 == 0) {
                [self.youLikeOtherArray addObject:self.youLikeModelArray[i]];
            }else{
                [self.youLikeTitleArray addObject:self.youLikeModelArray[i]];
            }
        }
       
        // 创建like的四个View
        [self creatLikeView];
        
        self.scrollModelArray = [ScrollModel modelConfigureWithDic:jsonDic];
        //  创建 滚动的scrollView
        [self creatImageView_ScrollView];
        
      self.modelDic = [MenuMainModel modelConfigureWithDic:jsonDic];
        self.keyArray = [MenuMainModel modelKeyConfigureDic:jsonDic];
        for (NSString *key in _keyArray) {
            NSLog(@"%@",key);
        }
        NSLog(@"%ld",self.keyArray.count);
       
       
      
//        //  第0个分区
        self.zeroArray = [NSMutableArray array];
        [self creatDataWithSection:0 count:4 quanju:self.zero modelArray:self.zeroArray];
        NSLog(@"0000%@",self.zeroArray);
        //  第1个分区
        self.twoArray = [NSMutableArray array];
        [self creatImageViewDataSection:1 count:2 quanju:self.two modelArray:self.twoArray];
        //  第2个分区
        self.fourArray = [NSMutableArray array];
        [self creatImageViewDataSection:2 count:2 quanju:self.four modelArray:self.fourArray];
        //  第3个分区
        if (self.keyArray[3] == nil || [self.keyArray[3] isEqualToString:@""]) {
            
        }else{
           self.fiveArray = [NSMutableArray array];
        [self creatImageViewDataSection:3 count:2 quanju:self.five modelArray:self.fiveArray]; 
        }
        
       
        
        
        
        
        //  第5个分区
                self.threeArray = [NSMutableArray array];
                [self creatDataWithSection:self.keyArray.count -3 count:4 quanju:self.three modelArray:self.threeArray];
                NSLog(@"%@",self.threeArray);
        
        //  第六个分区
        self.sixArray = [NSMutableArray array];
        [self creatDataWithSection:self.keyArray.count - 2 count:3 quanju:self.six modelArray:self.sixArray];
        NSLog(@"%@",self.sixArray);
        
        //  第7个分区
                self.oneArray = [NSMutableArray array];
                [self creatDataWithSection:self.keyArray.count -1 count:3 quanju:self.one modelArray:self.oneArray];
        
        //  结束 转菊花
        [self.tableView.mj_header endRefreshing];
        [self.collectionView reloadData];
        [self.goodfoodCollection reloadData];
         [self.tableView reloadData];
    
    } error:nil];
    
}

#pragma mark - 拼接图片数据 - 
- (void)creatImageViewDataSection:(NSInteger)section count:(int)count quanju:(int)quanqu modelArray:(NSMutableArray *)dataArray{
    NSString *key = self.keyArray[section];
    NSLog(@"%@",key);
    NSLog(@"%@",self.modelDic[key]);
    quanqu = 3;
    NSMutableArray *modelArray = [self.modelDic objectForKey:key];
    if (modelArray == nil) {
        return;
    }
    NSMutableArray *oneModelArray = [NSMutableArray array];
    for (int i = 0; i < 3; i++) {
        [oneModelArray addObject:[modelArray[i]content]];
    }
    [dataArray addObject:oneModelArray];
    for (int i = quanqu; i < modelArray.count; i = i+count) {
        NSMutableArray *smallArray = [NSMutableArray array];
        for (int j = i; j < i + count; j++) {
            [smallArray addObject:[modelArray[j] content]];
        }
        [dataArray addObject:smallArray];
    }
    
    quanqu += count;

}
#pragma mark - 拼接数据 -
- (void)creatDataWithSection:(NSInteger)section count:(int)count quanju:(int)quanqu modelArray:(NSMutableArray *)dataArray{
    
    NSString *key = self.keyArray[section];
    NSLog(@"%@",key);
    NSMutableArray *modelArray = [self.modelDic objectForKey:key];
    NSLog(@"!!!%@",modelArray);
    for ( int i = quanqu ; i < modelArray.count; i = i+count) {
        NSMutableArray *smallArray = [NSMutableArray array];
        for (int j = i; j < i + count; j++) {
            [smallArray addObject:[modelArray[j] content]];
        }
        [dataArray addObject:smallArray];
    }
    quanqu += count;
}


//  区头不定在那里一起滚动
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGFloat sectionHeaderHeight = 50;
    if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y> 0) {
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    }else
        if(scrollView.contentOffset.y >= sectionHeaderHeight){
            
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
            
        }
}
#pragma mark - 创建tableView -
- (void)creadTableView{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight - 70 - 50) style:(UITableViewStylePlain)];
    self.tableView.tableHeaderView = self.headView;
    //    self.tableView.backgroundColor = [UIColor magentaColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //  今日新品
    [self.tableView registerClass:[TodayNewProductTableViewCell class] forCellReuseIdentifier:@"TodayNewProductTableViewCell"];
    
    //  美食专家
    [self.tableView registerClass:[FoodSpecialistTableViewCell class] forCellReuseIdentifier:@"FoodSpecialistTableViewCell"];
    
    //下午茶情调  冰爽夏日 生活还有吃和远方
    [self.tableView registerClass:[TeaAndIcreAndLifeTableViewCell class] forCellReuseIdentifier:@"TeaAndIcreAndLifeTableViewCell"];
    //   推荐达人
    [self.tableView registerClass:[SuperManTableViewCell class] forCellReuseIdentifier:@"SuperManTableViewCell"];
    //   精选作品
    [self.tableView registerClass:[GoodFoodTableViewCell class] forCellReuseIdentifier:@"GoodFoodTableViewCell"];
    [self.leftView addSubview:_tableView];
}
#pragma mark - 返回tableView分区数 - 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.keyArray.count;
}
#pragma mark - 返回tableView每个分区的行数 - 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSString *key = self.keyArray[section];
//    if (section == 0) {
//        return 1;
////        return [self.modelDic[key]count] / 3;
//    }else if (section == 1){
//        return 1;
//    }else if (section == 2){
//        return 1;
////        return [self.modelDic[key]count] / 4;
//    }else if (section == 3){
//        return 1;
//    }else if (section == 4){
//        return 0;
//    }else if (section == 5){
//        return [self.modelDic[key] count] / 4;
//    }else if (section == 6){
//        return 1;
//    }
//     return [self.modelDic[key]count] / 3;
    
    if (section == self.keyArray.count - 1) {
        return 2;
    }
    if (section == self.keyArray.count - 3) {
        return 3;
    }
    if (section == self.keyArray.count - 4) {
        return 0;
    }
    return 1;
    
}
#pragma mark - 第二个分区的点击方法 - 
- (void)oneSectionTapAction0:(UITapGestureRecognizer *)tap{
    MenuTuijianChangjingDetailViewController *Vc = [[MenuTuijianChangjingDetailViewController alloc]init];
    NSString *key = self.keyArray[1];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[0] link] componentsSeparatedByString:@"#"];
    Vc.scene_id = [NSNumber numberWithInteger:[array[1] integerValue]];
    [self.navigationController pushViewController:Vc animated:YES];
}
- (void)oneSectionTapAction1:(UITapGestureRecognizer *)tap{
    MenuFirstDetailViewController *Vc = [[MenuFirstDetailViewController alloc]init];
    NSString *key = self.keyArray[1];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[3] link] componentsSeparatedByString:@"#"];
    Vc.dishes_id = array[1];
    [self.navigationController pushViewController:Vc animated:YES];
}
- (void)oneSectionTapAction2:(UITapGestureRecognizer *)tap{
    MenuFirstDetailViewController *Vc = [[MenuFirstDetailViewController alloc]init];
    NSString *key = self.keyArray[1];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[5] link] componentsSeparatedByString:@"#"];
    Vc.dishes_id = array[1];
    [self.navigationController pushViewController:Vc animated:YES];
}
- (void)oneSectionTapAction3:(UITapGestureRecognizer *)tap{
    MenuFirstDetailViewController *Vc = [[MenuFirstDetailViewController alloc]init];
    NSString *key = self.keyArray[1];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[7] link] componentsSeparatedByString:@"#"];
    Vc.dishes_id = array[1];
    [self.navigationController pushViewController:Vc animated:YES];
}
- (void)oneSectionTapAction4:(UITapGestureRecognizer *)tap{
    MenuFirstDetailViewController *Vc = [[MenuFirstDetailViewController alloc]init];
    NSString *key = self.keyArray[1];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[9] link] componentsSeparatedByString:@"#"];
    Vc.dishes_id = array[1];
    [self.navigationController pushViewController:Vc animated:YES];
}



- (void)oneSection2TapAction0:(UITapGestureRecognizer *)tap{
    MenuTuijianChangjingDetailViewController *Vc = [[MenuTuijianChangjingDetailViewController alloc]init];
    NSString *key = self.keyArray[2];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[0] link] componentsSeparatedByString:@"#"];
    Vc.scene_id = [NSNumber numberWithInteger:[array[1] integerValue]];
    [self.navigationController pushViewController:Vc animated:YES];
}
- (void)oneSection2TapAction1:(UITapGestureRecognizer *)tap{
    MenuFirstDetailViewController *Vc = [[MenuFirstDetailViewController alloc]init];
    NSString *key = self.keyArray[2];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[3] link] componentsSeparatedByString:@"#"];
    Vc.dishes_id = array[1];
    [self.navigationController pushViewController:Vc animated:YES];
}
- (void)oneSection2TapAction2:(UITapGestureRecognizer *)tap{
    MenuFirstDetailViewController *Vc = [[MenuFirstDetailViewController alloc]init];
    NSString *key = self.keyArray[2];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[5] link] componentsSeparatedByString:@"#"];
    Vc.dishes_id = array[1];
    [self.navigationController pushViewController:Vc animated:YES];
}
- (void)oneSection2TapAction3:(UITapGestureRecognizer *)tap{
    MenuFirstDetailViewController *Vc = [[MenuFirstDetailViewController alloc]init];
    NSString *key = self.keyArray[2];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[7] link] componentsSeparatedByString:@"#"];
    Vc.dishes_id = array[1];
    [self.navigationController pushViewController:Vc animated:YES];
}
- (void)oneSection2TapAction4:(UITapGestureRecognizer *)tap{
    MenuFirstDetailViewController *Vc = [[MenuFirstDetailViewController alloc]init];
    NSString *key = self.keyArray[2];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[9] link] componentsSeparatedByString:@"#"];
    Vc.dishes_id = array[1];
    [self.navigationController pushViewController:Vc animated:YES];
}


- (void)oneSection3TapAction0:(UITapGestureRecognizer *)tap{
    MenuTuijianChangjingDetailViewController *Vc = [[MenuTuijianChangjingDetailViewController alloc]init];
    NSString *key = self.keyArray[3];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[0] link] componentsSeparatedByString:@"#"];
    Vc.scene_id = [NSNumber numberWithInteger:[array[1] integerValue]];
    [self.navigationController pushViewController:Vc animated:YES];
}
- (void)oneSection3TapAction1:(UITapGestureRecognizer *)tap{
    MenuFirstDetailViewController *Vc = [[MenuFirstDetailViewController alloc]init];
    NSString *key = self.keyArray[3];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[3] link] componentsSeparatedByString:@"#"];
    Vc.dishes_id = array[1];
    [self.navigationController pushViewController:Vc animated:YES];
}
- (void)oneSection3TapAction2:(UITapGestureRecognizer *)tap{
    MenuFirstDetailViewController *Vc = [[MenuFirstDetailViewController alloc]init];
    NSString *key = self.keyArray[3];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[5] link] componentsSeparatedByString:@"#"];
    Vc.dishes_id = array[1];
    [self.navigationController pushViewController:Vc animated:YES];
}
- (void)oneSection3TapAction3:(UITapGestureRecognizer *)tap{
    MenuFirstDetailViewController *Vc = [[MenuFirstDetailViewController alloc]init];
    NSString *key = self.keyArray[3];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[7] link] componentsSeparatedByString:@"#"];
    Vc.dishes_id = array[1];
    [self.navigationController pushViewController:Vc animated:YES];
}
- (void)oneSection3TapAction4:(UITapGestureRecognizer *)tap{
    MenuFirstDetailViewController *Vc = [[MenuFirstDetailViewController alloc]init];
    NSString *key = self.keyArray[3];
    NSMutableArray *modelArray = self.modelDic[key];
    NSArray *array = [[modelArray[9] link] componentsSeparatedByString:@"#"];
    Vc.dishes_id = array[1];
    [self.navigationController pushViewController:Vc animated:YES];
}

#pragma mark - 返回cell - 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    if (indexPath.section == 0) {
        TodayNewProductTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TodayNewProductTableViewCell" forIndexPath:indexPath];
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    
        self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kWidth/3 * 1915 / 1277 + 30 + 50) collectionViewLayout:flowLayout];
        [self.collectionView registerClass:[MenuZeroCollectionViewCell class] forCellWithReuseIdentifier:@"MenuZeroCollectionViewCell"];
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        self.collectionView.backgroundColor = [UIColor whiteColor];
        [cell.contentView addSubview:_collectionView];
        
        return cell;
    }else if (indexPath.section == 1){
        TeaAndIcreAndLifeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TeaAndIcreAndLifeTableViewCell" forIndexPath:indexPath];
            [cell cellConfigureWithArray:self.twoArray desc:self.descArray[indexPath.section]];
        UITapGestureRecognizer *tap0 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSectionTapAction0:)];
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSectionTapAction1:)];
        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSectionTapAction2:)];
        UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSectionTapAction3:)];
        UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSectionTapAction4:)];
        cell.bigImageView.userInteractionEnabled = YES;
        [cell.bigImageView addGestureRecognizer:tap0];
        cell.imageView1.userInteractionEnabled = YES;
        [cell.imageView1 addGestureRecognizer:tap1];
        cell.imageView2.userInteractionEnabled = YES;
        [cell.imageView2 addGestureRecognizer:tap2];
        cell.imageView3.userInteractionEnabled = YES;
        [cell.imageView3 addGestureRecognizer:tap3];
        cell.imageView4.userInteractionEnabled = YES;
        [cell.imageView4 addGestureRecognizer:tap4];
            return cell;
       
        
    }else if (indexPath.section == 2 ){
        TeaAndIcreAndLifeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TeaAndIcreAndLifeTableViewCell" forIndexPath:indexPath];
        [cell cellConfigureWithArray:self.fourArray desc:self.descArray[indexPath.section]];
        
        UITapGestureRecognizer *tap0 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSection2TapAction0:)];
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSection2TapAction1:)];
        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSection2TapAction2:)];
        UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSection2TapAction3:)];
        UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSection2TapAction4:)];
        cell.bigImageView.userInteractionEnabled = YES;
        [cell.bigImageView addGestureRecognizer:tap0];
        cell.imageView1.userInteractionEnabled = YES;
        [cell.imageView1 addGestureRecognizer:tap1];
        cell.imageView2.userInteractionEnabled = YES;
        [cell.imageView2 addGestureRecognizer:tap2];
        cell.imageView3.userInteractionEnabled = YES;
        [cell.imageView3 addGestureRecognizer:tap3];
        cell.imageView4.userInteractionEnabled = YES;
        [cell.imageView4 addGestureRecognizer:tap4];
        
        return cell;
    }else if (indexPath.section == 3){
        
        if ([self.modelDic[self.keyArray[indexPath.section]] count]== 0) {
            return nil;
        }
        TeaAndIcreAndLifeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TeaAndIcreAndLifeTableViewCell" forIndexPath:indexPath];
     [cell cellConfigureWithArray:self.fiveArray desc:self.descArray[indexPath.section]];
        
        UITapGestureRecognizer *tap0 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSection3TapAction0:)];
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSection3TapAction1:)];
        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSection3TapAction2:)];
        UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSection3TapAction3:)];
        UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(oneSection3TapAction4:)];
        cell.bigImageView.userInteractionEnabled = YES;
        [cell.bigImageView addGestureRecognizer:tap0];
        cell.imageView1.userInteractionEnabled = YES;
        [cell.imageView1 addGestureRecognizer:tap1];
        cell.imageView2.userInteractionEnabled = YES;
        [cell.imageView2 addGestureRecognizer:tap2];
        cell.imageView3.userInteractionEnabled = YES;
        [cell.imageView3 addGestureRecognizer:tap3];
        cell.imageView4.userInteractionEnabled = YES;
        [cell.imageView4 addGestureRecognizer:tap4];
        return cell;
    }else if (indexPath.section == self.keyArray.count - 4 ){
        return nil;
    }else if (indexPath.section == self.keyArray.count -3 ){
        
        SuperManTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SuperManTableViewCell" forIndexPath:indexPath ];
                [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:self.threeArray[indexPath.row][0]] placeholderImage:nil completed:nil];
                cell.nameLabel.text = self.threeArray[indexPath.row][1];
                cell.contentLabel.text = self.threeArray[indexPath.row][2];
                cell.fanceLabel.text = self.threeArray[indexPath.row][3];
        
        return cell;
    }else if (indexPath.section == self.keyArray.count -2){
        GoodFoodTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GoodFoodTableViewCell" forIndexPath:indexPath];
        
         UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        
        self.goodfoodCollection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kWidth/3 + 30 + 30) collectionViewLayout:flowLayout];
        [self.goodfoodCollection registerClass:[MenuSixCollectionViewCell class] forCellWithReuseIdentifier:@"MenuSixCollectionViewCell"];
        self.goodfoodCollection.delegate = self;
        self.goodfoodCollection.dataSource = self;
        self.goodfoodCollection.backgroundColor = [UIColor whiteColor];
        [cell.contentView addSubview:_goodfoodCollection];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, kWidth/3 + 30 + 30, kWidth - 40, 30)];
        label.textColor = [UIColor grayColor];
        label.font = [UIFont systemFontOfSize:14];
        label.text = self.descArray[indexPath.section];
        label.textAlignment = NSTextAlignmentCenter;
        [cell.contentView addSubview:label];
        
        return cell;

    }else{
        
        FoodSpecialistTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FoodSpecialistTableViewCell" forIndexPath:indexPath];
        
                [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:self.oneArray[indexPath.row][0]] placeholderImage:nil completed:nil];
                cell.titleLabel.text = self.oneArray[indexPath.row][1];
                cell.contentLabel.text = self.oneArray[indexPath.row][2];

        return cell;
    }
   
}


#pragma mark - 返回cell高度 -
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return kWidth/3 * 1915 / 1277 + 30 + 50 ;
    }else if (indexPath.section == 1){
        return 200;
    }else if (indexPath.section == 2){
        return 200;
    }else if (indexPath.section == 3){
        if ([self.modelDic[self.keyArray[indexPath.section]] count] == 0) {
            return 0;
        }
        return 200;
    }else if (indexPath.section == self.keyArray.count - 3){
        return 100;
    }else if (indexPath.section == self.keyArray.count - 2){
        return kWidth/3 + 90;
    }else if (indexPath.section == self.keyArray.count - 1){
        return 200;
    }
    return 0;
}


#pragma mark - 返回区头 - 
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *topView = [[UIView alloc]init];
//    topView.backgroundColor = [UIColor magentaColor];
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kWidth / 2 - 75, 5, 150, 30)];
//    titleLabel.backgroundColor = [UIColor blueColor];
    titleLabel.text = self.keyArray[section];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [topView addSubview:titleLabel];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(kWidth / 2 - 75 + 150 + 30, 10, 20, 20)];
    imageView.image = [UIImage imageNamed:@"menutiaozhuan"];
    [topView addSubview:imageView];
    topView.userInteractionEnabled = YES;
    topView.tag = 400 + section;
    UITapGestureRecognizer *headViewTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headViewTapAction:)];
    [topView addGestureRecognizer:headViewTap];
    
    
//    topView.backgroundColor = [UIColor magentaColor];
    return topView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}
#pragma mark - 表头的点击方法 - 
- (void)headViewTapAction:(UITapGestureRecognizer *)tap{
    if (tap.view.tag == 400) {
        //  methodName=SceneInfo&scene_id=51&token=&user_id=&version=4.4
        MenuTuijianChangjingDetailViewController *Vc = [[MenuTuijianChangjingDetailViewController alloc]init];
        Vc.scene_id = [NSNumber numberWithInteger:[self.linkArray[0]  integerValue]];
        
        
//        Vc.scene_id = @51;
        [self.navigationController pushViewController:Vc animated:YES];
    }
    if (tap.view.tag == 401) {
        // methodName=SceneInfo&scene_id=129&token=&user_id=&version=4.4
        MenuTuijianChangjingDetailViewController *Vc = [[MenuTuijianChangjingDetailViewController alloc]init];
//        Vc.scene_id = @129;
        Vc.scene_id = [NSNumber numberWithInteger:[self.linkArray[1]  integerValue]];
        [self.navigationController pushViewController:Vc animated:YES];
    }
    if (tap.view.tag == 402) {
        //  methodName=SceneInfo&scene_id=181&token=&user_id=&version=4.4
        MenuTuijianChangjingDetailViewController *Vc = [[MenuTuijianChangjingDetailViewController alloc]init];
//        Vc.scene_id = @181;
        Vc.scene_id = [NSNumber numberWithInteger:[self.linkArray[2]  integerValue]];
        [self.navigationController pushViewController:Vc animated:YES];
    }
    if ([self.modelDic[self.keyArray[3]] count] != 0) {
        if (tap.view.tag == 403) {
        //methodName=SceneInfo&scene_id=147&token=&user_id=&version=4.4
        MenuTuijianChangjingDetailViewController *Vc = [[MenuTuijianChangjingDetailViewController alloc]init];
//        Vc.scene_id = @147;
            Vc.scene_id = [NSNumber numberWithInteger:[self.linkArray[3]  integerValue]];
        [self.navigationController pushViewController:Vc animated:YES];
    }
    }
    
    if (tap.view.tag == 400 + self.keyArray.count - 4) {
        MenuTuiJianChangJingViewController *Vc = [[MenuTuiJianChangJingViewController alloc]init];
        [self.navigationController pushViewController:Vc animated:YES];
    }
    if (tap.view.tag == 400 + self.keyArray.count -3) {
        //  methodName=TalentRecommend&page=1&size=10&token=&user_id=&version=4.4
        // 推荐大人
        MenuDarenViewController *darenVc = [[MenuDarenViewController alloc]init];
        [self.navigationController pushViewController:darenVc animated:YES];
    }
    if (tap.view.tag == 400 + self.keyArray.count - 2) {
        //  is_marrow=1&methodName=ShequList&page=1&size=10&token=&user_id=&version=4.4
        MenuJingXuanMainViewController *Vc = [[MenuJingXuanMainViewController alloc]init];
        [self.navigationController pushViewController:Vc animated:YES];
    }
    if (tap.view.tag == 400 + self.keyArray.count -1) {
        MenuZhuanTiMainViewController *Vc = [[MenuZhuanTiMainViewController alloc]init];
        [self.navigationController pushViewController:Vc animated:YES];
        // methodName=TopicList&page=1&size=10&token=&type=1&user_id=&version=4.4
    }
}
#pragma mark - 创建可以滑动的imageViewscrolView
- (void)creatImageView_ScrollView{
    
    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 150 + kWidth / 4 + 10, kWidth, 80)];
    scrollView.bounces = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.contentSize = CGSizeMake(kWidth *2, 80);
    [self.headView addSubview:scrollView];
    for (int i = 0; i < 4; i++) {
        UITapGestureRecognizer *scrollTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(scrollTapAction:)];
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(kWidth /2 *i, 0, kWidth / 2, 80)];
        imageView.userInteractionEnabled = YES;
        imageView.tag = 300 + i;
        [imageView sd_setImageWithURL:[NSURL URLWithString:[self.scrollModelArray[i] content]] placeholderImage:nil completed:nil];
        imageView.backgroundColor = [UIColor blueColor];
        [imageView addGestureRecognizer:scrollTap];
        [scrollView addSubview:imageView];
    }
}

#pragma mark - like手势的点击方法 -
- (void)tapAction:(UITapGestureRecognizer *)tap{
    if (tap.view.tag == 200) {
        MenuTuiJianXInShouViewController *xinshouVc = [[MenuTuiJianXInShouViewController alloc]init];
        xinshouVc.webViewUrlString = self.xinshourumenUrl;
        [self.navigationController pushViewController:xinshouVc animated:YES];
    }else if (tap.view.tag == 201){
        MenuTuiJIanShiCaiViewController *shicaiVc = [[MenuTuiJIanShiCaiViewController alloc]init];
      NSString *key = self.shiCaiTitleArray[0];
        NSMutableArray *modelArray = self.shiCaiDic[key];
        shicaiVc.modelArray = modelArray;
        [self.navigationController pushViewController:shicaiVc animated:YES];
    }else if (tap.view.tag == 202){
        MenuTuiJianChangJingViewController *changjingVc = [[MenuTuiJianChangJingViewController alloc]init];
        [self.navigationController pushViewController:changjingVc animated:YES];
    }else{
        MenuTuiJIanCaiNiViewController *cainiVc = [[MenuTuiJIanCaiNiViewController alloc]init];
        [self.navigationController pushViewController:cainiVc animated:YES];
    }
    NSLog(@"111");
}
#pragma mark - 4个scrolView手势的点击方法
- (void)scrollTapAction:(UITapGestureRecognizer *)tap{
    if (tap.view.tag == 300) {
        
    }else if (tap.view.tag == 301){
        
    }else if (tap.view.tag == 302){
        
    }else{
        
    }
}
#pragma mark - 创建4个like的图片 -
- (void)creatLikeView{
    
    
    for (int i = 0; i < 4; i++) {
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
        UIView *myView = [[UIView alloc]initWithFrame:CGRectMake(kWidth / 4 * i, 150, kWidth / 4, kWidth / 4)];
        [self.headView addSubview:myView];
        
        UIImageView *imageView = [[UIImageView alloc]init];
        UILabel *titleLabel = [[UILabel alloc]init];
        imageView.userInteractionEnabled = YES;
        [imageView addGestureRecognizer:tap];
        imageView.frame  = CGRectMake(15, 10, kWidth / 4 - 30, kWidth / 4 - 30);
        [imageView sd_setImageWithURL:[NSURL URLWithString:[self.youLikeOtherArray[i] content]] placeholderImage:nil completed:nil];
        titleLabel.frame = CGRectMake(0,kWidth / 4 - 20 , kWidth / 4, 20);
        //        titleLabel.backgroundColor = [UIColor grayColor];
        titleLabel.text = [self.youLikeTitleArray[i] content];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.textColor = [UIColor blackColor];
        [myView addSubview:titleLabel];
        imageView.tag = 200 + i;
//                imageView.backgroundColor = [UIColor blueColor];
        [myView addSubview:imageView];
    }
}
#pragma mark - 创建 searchBarVc - 
- (void)creatSearchBarVc{
    self.searchBar = [[UISearchBar alloc]init];
    self.searchBar.frame = CGRectMake(kWidth / 2 - 150, 110, 300, 30);
    [self.headView addSubview:_searchBar];
}
#pragma mark - 穿件滚动视图 - 
- (void)creatScrollView{
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 70, kWidth, kHeight - 70  -50)];
    self.scrollView.contentOffset = CGPointMake(0, 0);
    self.scrollView.contentSize = CGSizeMake(kWidth * 3, kHeight - 70 -50);
    self.scrollView.backgroundColor = [UIColor purpleColor];
        self.scrollView.showsHorizontalScrollIndicator = NO;
        self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.bounces = NO;
    self.scrollView.delegate = self;
    
    [self.view addSubview:_scrollView];
    
    //  添加三个视图
    self.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight - 70 - 50)];
    _leftView.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:_leftView];
    
    self.centerView = [[UIView alloc]initWithFrame:CGRectMake(kWidth, 0, kWidth, kHeight - 70 - 50)];
    self.centerView.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:_centerView];
    
    self.rightView = [[UIView alloc]initWithFrame:CGRectMake(kWidth * 2, 0, kWidth, kHeight - 70 - 50)];
//    self.rightView.backgroundColor = [UIColor cyanColor];
    [self.scrollView addSubview:_rightView];
    
}
#pragma mark - 创建上面的button -
- (void)creatTopView{
    // 横条
    self.changeView = [[UIView alloc]initWithFrame:CGRectMake(kWidth / 2 - 20 - 30 - 40 + 5, 65, 30, 5)];
    self.changeView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:_changeView];
    // 扫描二维码
    UIButton *leftButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    leftButton.frame = CGRectMake(20, 40, 25, 25);
    [leftButton setBackgroundImage:[UIImage imageNamed:@"menusaoma"] forState:(UIControlStateNormal)];
    [leftButton addTarget:self action:@selector(leftButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:leftButton];
    
    // 推荐
    UIButton *button1 = [UIButton buttonWithType:(UIButtonTypeSystem)];
    button1.frame = CGRectMake(kWidth / 2 - 20 - 30 - 40, 30, 40, 40);
    [button1 addTarget:self action:@selector(button1Action:) forControlEvents:(UIControlEventTouchUpInside)];
    [button1 setTitle:@"推荐" forState:(UIControlStateNormal)];
    [self.view addSubview:button1];
    
    // 食材
    UIButton *button2 = [UIButton buttonWithType:(UIButtonTypeSystem)];
    button2.frame = CGRectMake(kWidth / 2 - 20, 30, 40, 40);
    [button2 addTarget:self action:@selector(button2Action:) forControlEvents:(UIControlEventTouchUpInside)];
    [button2 setTitle:@"食材" forState:(UIControlStateNormal)];
    [self.view addSubview:button2];
    
    // 分类
    UIButton *button3 = [UIButton buttonWithType:(UIButtonTypeSystem)];
    button3.frame = CGRectMake(kWidth / 2 + 20 + 30, 30, 40, 40);
    [button3 addTarget:self action:@selector(button3Action:) forControlEvents:(UIControlEventTouchUpInside)];
    [button3 setTitle:@"分类" forState:(UIControlStateNormal)];
    [self.view addSubview:button3];
    // 搜索
    UIButton *rightButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    rightButton.frame = CGRectMake(kWidth - 20 - 20, 40, 25, 25);
    [rightButton setBackgroundImage:[UIImage imageNamed:@"menusousuo"] forState:(UIControlStateNormal)];
    [rightButton addTarget:self action:@selector(rightButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:rightButton];
    
}
#pragma mark - 二维码 - 
- (void)leftButtonAction:(UIButton *)button{
    MenuErweimaViewController *Vc = [[MenuErweimaViewController alloc]init];
    [self.navigationController pushViewController:Vc animated:YES];
}
#pragma mark - 推荐 - 
- (void)button1Action:(UIButton *)button{
    self.changeView.frame = CGRectMake(kWidth / 2 - 20 - 30 - 40 + 5, 65, 30, 5);
    self.scrollView.contentOffset = CGPointMake(0, 0);
}
#pragma mark - 食材 -
- (void)button2Action:(UIButton *)button{
    self.changeView.frame = CGRectMake(kWidth / 2 - 20 + 5, 65, 30, 5);
   self.scrollView.contentOffset = CGPointMake(kWidth, 0);
 
    
    
}

#pragma mark - 分类 -
- (void)button3Action:(UIButton *)button{
    self.changeView.frame = CGRectMake(kWidth / 2 + 20 + 30 + 5, 65, 30, 5);
   self.scrollView.contentOffset = CGPointMake(kWidth * 2, 0);
}
#pragma mark - 搜索 - 
- (void)rightButtonAction:(UIButton *)button{
    
}

#pragma mark - 滚动结束的代理方法 -
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    NSLog(@"a");
    if (scrollView != self.scrollView) {
        return;
    }
   NSInteger index = scrollView.contentOffset.x / kWidth;
    if (index == 0) {
        self.changeView.frame = CGRectMake(kWidth / 2 - 20 - 30 - 40 + 5, 65, 30, 5);
    }else if (index == 1){
        self.changeView.frame = CGRectMake(kWidth / 2 - 20 + 5, 65, 30, 5);
    }else if (index == 2){
         self.changeView.frame = CGRectMake(kWidth / 2 + 20 + 30 + 5, 65, 30, 5);
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
